#ifndef __DATABASE_COMPARE_EVENT_HPP__
#define __DATABASE_COMPARE_EVENT_HPP__

#ifdef ENABLE_DB_JUDGE

#include "base_event.hpp"

namespace run_code_event_space {

struct database_compare_event : base_event<database_compare_event>  {
    template <class U>
    ProcessStatus execute_impl(run_code_context_t<U>& context, const string& resultFile);
};

template <class U>
ProcessStatus database_compare_event::execute_impl(run_code_context_t<U>& context, const string& resultFile) {
    if constexpr (contains_v<U, DatabaseModifyJudge, DatabaseSelectJudge>) {
        double eps = context.params.eps.empty() ? -1 : strtod(context.params.eps.c_str(), NULL);
        auto res = context.get_latest_status().extern_info->equal(*JsonObject::decoder(fileToStr(resultFile)), eps, !(context.params.compareFlag & IGNPRE_LIST_ORDER));
        if (res) {
            return ProcessStatus{ .result = RUN_OK };
        }
    return ProcessStatus{ .result = WA, .error = "database compare fail" };
    }
    return ProcessStatus{ .result = RUN_FAIL, .error = "no support"};
}

}

#endif

#endif /* __DATABASE_COMPARE_EVENT_HPP__ */
